<?php

namespace Admin\Model;

use Think\Model;

class MemberModel extends Model {

    protected $tableName = 'member';
    protected $pk = 'id';

    
    //保存设置
    public function dosave($datas = array()) {
        $fields = dict('', 'Setting');   //获取当前配置选项列表
        $settingField = array_keys($fields);
        $this->where("`key` not in('" . implode("','", $settingField) . "')")->delete(); //删除多余属性
        $where = "`key` in('" . implode("','", $settingField) . "')";
        $list = $this->where($where)->getField('key', true); //从数据库中获取设置信息
        if (!is_array($list))
            $list = array();
        $result = false;
        foreach ($datas as $data) {
            switch ($data['key']) {
                case 'SAVE_LOG_OPEN': //后台日志过滤
                    $data['value'] = $data['value'] == '开启' ? '1' : '0';
                    break;
            }

            if (in_array($data['key'], $list)) {
                $state = $this->where(array('key' => $data['key']))->save($data);
            } else {
                $state = $this->add($data);
            }
            if ($state)
                $result = true;
        }
        $this->clearCatche(); //有修改时清空缓存
        return $result;
    }

}
